package com.tcs.test.executor.pool;

import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.tcs.test.executor.base.BeseExecutorRun;

public class PoolTest1 extends BeseExecutorRun {
	
	private final Logger logger = LoggerFactory.getLogger(PoolTest1.class);

	@Override
	protected void service() {
		ExecutorService pool = Executors.newFixedThreadPool(10);
		for (int i = 0; i < 10; i++) {
			pool.submit(new Run1());
		}
		List<Runnable> list = pool.shutdownNow();
		logger.info(" list : {} " , list.size());
		while (true) {
			if (pool.isTerminated()) {
				logger.info("都已关闭!!!");
				break;
			}
		}
	}

	@Test
	public void test1() {
		try {
			super.go();
		} catch (InterruptedException e) {
			logger.error("" , e);
		}
	}
	
	class Run1 implements Runnable {

		@Override
		public void run() {
			try {
				while (true) {
					Thread.sleep(1 * 1000L);
					logger.info(" 线程 : {} 正在运行" , Thread.currentThread().getName());
				}
			} catch (InterruptedException e) {
				logger.error("" , e);
				return;
			} finally {
				logger.info(" 是否活着 {} " , Thread.currentThread().isInterrupted());
			}
		}
	}
}